{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "f9547b88",
   "metadata": {},
   "outputs": [],
   "source": [
    "API_KEY = 'BP0btXKGGNki1HzFl8nYy9gS'\n",
    "API_KEY= 'hddu9H4TUzUzvOIe8bhxUMLNpqZ5fQT6'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "44711652",
   "metadata": {},
   "outputs": [],
   "source": [
    "from baidu_speech import fetch_token,asr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "f280b7f7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "token http response http code : 401\n"
     ]
    },
    {
     "ename": "NameError",
     "evalue": "name 'DemoError' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m/var/folders/nq/_w7p6d095mvfvhv54lvfytjc0000gn/T/ipykernel_58061/2403355649.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mxu_token\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfetch_token\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mAPI_KEY\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mAPI_KEY\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      2\u001b[0m \u001b[0mxu_token\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/API/week13/baidu_speech.py\u001b[0m in \u001b[0;36mfetch_token\u001b[0;34m(API_KEY, SECRET_KEY)\u001b[0m\n\u001b[1;32m     40\u001b[0m     \u001b[0;32mif\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;34m'access_token'\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mkeys\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0;34m'scope'\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mkeys\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     41\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0mSCOPE\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;32mnot\u001b[0m \u001b[0mSCOPE\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'scope'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msplit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m' '\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m  \u001b[0;31m# SCOPE = False 忽略检查\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 42\u001b[0;31m             \u001b[0;32mraise\u001b[0m \u001b[0mDemoError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'scope is not correct'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     43\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'access_token'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     44\u001b[0m     \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mNameError\u001b[0m: name 'DemoError' is not defined"
     ]
    }
   ],
   "source": [
    "xu_token = fetch_token(API_KEY,API_KEY)\n",
    "xu_token"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "83ae3eea",
   "metadata": {},
   "outputs": [],
   "source": [
    "TL_key = \"{\n",
    "\t\"reqType\":0,\n",
    "    \"perception\": {\n",
    "        \"inputText\": {\n",
    "            \"text\": \"附近的酒店\"\n",
    "        },\n",
    "        \"inputImage\": {\n",
    "            \"url\": \"imageUrl\"\n",
    "        },\n",
    "        \"selfInfo\": {\n",
    "            \"location\": {\n",
    "                \"city\": \"北京\",\n",
    "                \"province\": \"北京\",\n",
    "                \"street\": \"信息路\"\n",
    "            }\n",
    "        }\n",
    "    },\n",
    "    \"userInfo\": {\n",
    "        \"apiKey\": \"\",\n",
    "        \"userId\": \"\"\n",
    "    }\n",
    "}\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8e4814e7",
   "metadata": {},
   "outputs": [],
   "source": [
    "TL_key = \"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "29f4869b",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "import requests \n",
    "\n",
    "host = 'http://openapi.turingapi.com/openapi/api/v2'\n",
    "payload = {\n",
    "   \n",
    "}\n",
    "  \n",
    "response = requests.get(host,params=payload)\n",
    "if response:\n",
    "    print(response.json())"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
